/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pessoas.presenter;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import pessoas.collection.Contatos;
import pessoas.collection.ContatosInvalidos;
import pessoas.collection.Usuarios;
import pessoas.model.Usuario;
import pessoas.serializacao.serializacaoArquivo;
import pessoas.view.MainView;

/**
 *
 * @author Bush
 */
public class MainPresenter {

    private MainView view;
    private Contatos contatos;
    private ContatosInvalidos invalidos;
    private Usuarios usuarios;
    private Usuario usuario;
    private serializacaoArquivo serializacao;
    
    public MainPresenter(Usuario u, Usuarios usu) {
        view = new MainView();
        serializacao = new serializacaoArquivo();
        
        try {
            contatos = Contatos.getInstancia();
            this.usuarios = usu;
            this.usuario = u;
            this.invalidos = ContatosInvalidos.getInstancia();
        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }

        view.getBtnUsuario().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new UsuarioPresenter(usuarios);
            }
        });
        
        view.getBtnGrafico().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new ExibeGraficoPresenter(contatos);
            }
        });
        
        view.getBtnAdicionar().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new ContatoPresenter(usuario,contatos,null,false);                
            }
        });
        view.getBtnListarPessoa().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new ListaContatosPresenter(usuario, contatos, null);
            }
        });
        view.getBtnImportarcao().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new ImportacaoXMLPresenter(usuario,contatos,invalidos);                
            }
        });
        
        view.getBtnExportar().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new ExportarPresenter(usuario,contatos);
            }
        });
        
        view.getBtnContatosInvalidos().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new ContatosInvalidosPresenter(usuario,contatos, invalidos);
            }
        });
        
         view.getBtnLog().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new ConfiguracoesLogPresenter();
            }
        });
         
        view.getBtnSair().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                view.setVisible(false);
                view.dispose();
            }
        });

        view.setExtendedState(JFrame.MAXIMIZED_BOTH);  
        view.setLocationRelativeTo(view);
        view.setVisible(true);
    }   

}
